package cn.neusoft.controller;

import cn.neusoft.pojo.Business;

import cn.neusoft.query.BaseQuery;
import cn.neusoft.query.BusinessQuery;
import cn.neusoft.service.IBaseService;
import cn.neusoft.service.IBusinessService;
import cn.neusoft.vo.ResultBean;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;



public class BaseController<T,W>{
	@Autowired
	IBaseService<T> baseService;
	@PostMapping      //  请求方式 + 请求路径   post  /business
	public ResultBean save(@RequestBody T t) throws Exception {
		return baseService.add(t);
		//这里一会再进行改动
	}

	@DeleteMapping("/{id}")
	public ResultBean delete(@PathVariable("id") Integer id) throws Exception {
		return baseService.delete(id);
	}
	@GetMapping("/{id}")
	public ResultBean getById (@PathVariable("id") Integer id) throws Exception {
		return baseService.getById(id);
	}
	@PostMapping("/all")
	public <W extends BaseQuery> ResultBean getAll (@RequestBody W baseQuery) throws Exception {
		//传过来的是一个子类的对象，父类在进行接收
		//自动发生向上转型
		return baseService.getAll(baseQuery);
	}
	@GetMapping("/batch")
	public ResultBean getBatchDel(@RequestBody List<Integer> list) throws Exception {
		//因为在前端的时候，直接变成19，21的形式了，在后端只需要进行转换即可
		return baseService.batchDel(list);
	}
}
